#include "client_conversation.h"

ClientConversation::ClientConversation(Socket* s, Mutex* general_mutex) {
	this->s = s;
	this->general_mutex = general_mutex;

}

ClientConversation::~ClientConversation() {
	delete s;

}

string ClientConversation::WaitForLogin(unsigned int max_tries) {
	string buffer;
	string user_name;
	unsigned int actual_try = 0;
	bool login_ok = false;
	//Salgo del while cuando llegue al maximo de intentos o logre loggear
	while ((actual_try < max_tries) && !login_ok) {
		s->Recv('\n', &buffer);
		/*MsgDecoder decoder(&buffer);
		 int decode_result = decoder.Decode();*/
		/* if (decode_result==REGISTER_ID) {
		 * user_name=LogUser(parametros...);
		 * s->Send(Logging-ok o Logging-Error);
		 }
		 }*/
	}
	if (!login_ok) throw CantLoginException();
	return user_name;
}

void ClientConversation::run() {
	string buffer;
	string user_name;
	//Veces que permite loggearse incorrectamente
	unsigned int max_login_tries=10;
	//Espero por loggeo de usuario
	user_name=WaitForLogin(max_login_tries);
	//Ciclo del programa


}


